#include "Light.fx"
 
 
cbuffer cbPerFrame
{
	Light gLight;
	float3 gEyePosW;
};

cbuffer cbPerObject
{
	float4x4	gWorld;
	float4x4	gProj;
	float4x4	gView;
	float4x4	gWVP; 
	//float4x4	gTexMtx;
	float4		g_Diffuse;
	float4		g_Spec;
};


SamplerState gTriLinearSam
{
	Filter = MIN_MAG_MIP_LINEAR;
};

struct VS_IN
{
	float3 posL    : POSITION;
	float3 normalL : NORMAL;
	//float2 texC    : TEXCOORD;
};

struct VS_OUT
{
	float4 posH    : SV_POSITION;
    float3 posW    : POSITION;
    float3 normalW : NORMAL;
   // float2 texC    : TEXCOORD;
};
 
VS_OUT VS(VS_IN vIn)
{
	VS_OUT vOut;
	
	// Transform to world space space.
	vOut.posW    = mul(float4(vIn.posL, 1.0f), gWorld);
	vOut.normalW = mul(float4(vIn.normalL, 0.0f), gWorld);
		
	float4x4 WVP = mul( mul(gWorld,gView) , gProj );
	// Transform to homogeneous clip space.
	vOut.posH = mul(float4(vIn.posL, 1.0f), WVP);
	
	// Output vertex attributes for interpolation across triangle.
	//vOut.texC  = mul(float4(vIn.texC, 0.0f, 1.0f), gTexMtx);
	
	return vOut;
}

float4 PS(VS_OUT pIn) : SV_Target
{
	//return g_Diffuse;
	// Get materials from texture maps.
	//float4 diffuse = gDiffuseMap.Sample( gTriLinearSam, pIn.texC );
	//float4 spec    = gSpecMap.Sample( gTriLinearSam, pIn.texC );

	// Map [0,1] --> [0,256]
	//g_Spec.a *= 256.0f;
	
	//float4 spec = g_Spec;
	//spec.a *= 256.0f;

	// Interpolating normal can make it not be of unit length so normalize it.
    float3 normalW = normalize(pIn.normalW);
    
	// Compute the lit color for this pixel.
    SurfaceInfo v = {pIn.posW, normalW, g_Diffuse, g_Spec};
	//SurfaceInfo v = {pIn.posW, normalW, g_Diffuse, spec};
	float3 litColor = ParallelLight(v, gLight, gEyePosW);
    
	//return float4(0.0f,0.0f,0.0f,g_Diffuse.a);
	return float4(litColor, g_Diffuse.a);
}

technique10 ParallelLighting
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}
